﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace WZVTC.SoftDev.WebUtility
{
    public class DDDFWAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
        {
            base.OnAuthorization(actionContext);
        }
        protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext)
        {
            bool result= base.IsAuthorized(actionContext);
            IEnumerable<string> token=new List<string>();
            IEnumerable<string> userID=new List<string>();
            if (actionContext.Request.Headers.TryGetValues("Token", out token)
                && actionContext.Request.Headers.TryGetValues("userID",out userID))
            {
                  result = JWTHelper.Verify(token.First(),userID.First());
            }
            else result = false;
               
            return result;
        }

       
    }
}
